<?php
	class Mstores extends Model {
	
		function __construct() {
			parent::Model();
		}
		
		function getAllStores() {
			$query = $this->db->get('store');
			if ($query->num_rows() > 0){
				return $query->result(); 
			} else {
				show_error('Database is Empty!');
			}  
		}
		
		function getStore($id){
			$options = array('id' => $id);
			$query = $this->db->getwhere('store',$options,1);
			if ($query->num_rows() > 0){
				return $query->result(); 
			}   
		}
		
		function addStore(){
			$data = array( 
				'Name' => $_POST['name'],
				'city_id' => $_POST['city_id'],
				'user_id' => $_POST['user_id'],
			);
			$data['created_at'] = date ("Y-m-d H:i:s");
			$this->db->insert('store', $data);	
		}
		
		function updateStore($id){
			$data = array( 
				'Name' => $_POST['name'],
				'city_id' => $_POST['city_id'],
				'user_id' => $_POST['user_id'],
				);
			$data['updated_at'] = date ("Y-m-d H:i:s");
			$this->db->where('id', $id);
			$this->db->update('store', $data);	
		}
		
		function deleteStores($id){
			$this->db->where('id', $id);
			$this->db->delete('store');
		}
	}
?>